//
//  drawImage.m
//  autoMoveView
//
//  Created by Yeming on 13-9-15.
//  Copyright (c) 2013年 Yeming. All rights reserved.
//

#import "drawImage.h"
#import <QuartzCore/QuartzCore.h>
@implementation drawImage

- (id)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self) {
        // Initialization code
    }
    return self;
}

/*
// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
- (void)drawRect:(CGRect)rect
{
    // Drawing code
}
*/
-(void)drawRect:(CGRect)rect
{
//    UIImage *image=[[UIImage imageNamed:@"erping1.jpg"] resizableImageWithCapInsets:UIEdgeInsetsMake(0,13,0,13) resizingMode:nil];
//
    
    self.clipsToBounds=YES;
    
//    CGImageRef ref=CGImageCreateCopyWithColorSpace(image.CGImage, colorRef);
//    
//    CGImageCreateWithImageInRect(ref, CGRectMake(10, 10, 20, 20));
//    UIImage *newImage=[UIImage imageWithCGImage:ref];
//    UIImageView *imageV=[[UIImageView alloc] initWithFrame:CGRectMake(10, 10, 200, 200)];
//    imageV.image=newImage;
//    imageV.contentMode=1;
//    [self addSubview:imageV ];
    

//     CGPoint center = CGPointMake(self.frame.size.width / 2.0, self.frame.size.height / 2.0);
//    CGColorSpaceRef colorSpace = CGColorSpaceCreateDeviceRGB();
//    CGContextRef context = CGBitmapContextCreate(nil,self.frame.size.width,self.frame.size.height,8,0, colorSpace,kCGImageAlphaPremultipliedLast);
//    CFRelease(colorSpace);
//    
//    CGContextSetStrokeColorWithColor(context, [[UIColor colorWithRed:1.0 green:1.0 blue:1.0 alpha:0.7] CGColor]);
//    CGContextBeginPath(context);
//    CGContextAddArc(context, center.x, center.y, center.x , 0, 2 * M_PI, 0);
//    CGContextClosePath(context);
//    CGContextSetLineWidth(context, 15.0);
//    CGContextStrokePath(context);
//    
//    
//    // convert the context into a CGImageRef
//    CGImageRef image = CGBitmapContextCreateImage(context);
//    CGContextRelease(context);
//    UIImage* image2 = [UIImage imageWithCGImage:image];
//    UIImageView *imgv =[[UIImageView alloc] initWithFrame:CGRectMake(0,0, self.frame.size.width , self.frame.size.height)];
//    imgv.center = CGPointMake(self.frame.size.width/2, self.frame.size.height/2);
//    imgv.image = image2;
//    [self addSubview:imgv];
    [self drawCircle];
    
    
    
    
    
}
-(void)drawCircle
{
  //1. one way
   // self.clipsToBounds=YES;
//    UIImageView *bac=[[UIImageView alloc] initWithFrame:CGRectMake(0, 0, self.frame.size.width, self.frame.size.height)];
//    bac.image=[UIImage imageNamed:@"erping1.jpg"];
//    [self addSubview:bac];
//    
//    self.layer.cornerRadius=50;
//    CGColorSpaceRef colorRef=CGColorSpaceCreateDeviceRGB();
//    CGContextRef ref=CGBitmapContextCreate(nil, self.frame.size.width, self.frame.size.height, 8, 0, colorRef, kCGImageAlphaPremultipliedLast);
//    CGContextSetStrokeColorWithColor(ref, [UIColor blueColor].CGColor);
//    CGContextBeginPath(ref);
//    
//    CGContextAddArc(ref, self.frame.size.width/2 , self.frame.size.height/2, self.frame.size.width/2, 0, 2*M_PI, 0);
//    CGContextClosePath(ref);
//    CGContextSetLineWidth(ref, 5);
//    CGContextStrokePath(ref);
//    CGImageRef imageRef=CGBitmapContextCreateImage(ref);
//    
//    UIImage *image=[UIImage imageWithCGImage:imageRef];
//    
//    UIImageView *imageV=[[UIImageView alloc] initWithFrame:CGRectMake(0, 0, self.frame.size.width, self.frame.size.height)];
//    imageV.center=CGPointMake(self.frame.size.width/2, self.frame.size.height/2);
//    imageV.contentMode=1;
//    imageV.image=image;
//    [self addSubview:imageV];
    
    //2. way
//    UIImage *image=[UIImage imageNamed:@"erping1.jpg"];
//    CGImageRef imgRef=CGImageCreateCopy(image.CGImage);
//   ;
//    NSString *path=[[NSBundle mainBundle] pathForResource:@"erping1" ofType:@"jpg"];
//    NSData *date=[NSData dataWithContentsOfFile:path];
//    
    
//    CGContextRef ref=CGBitmapContextCreate(date, <#size_t width#>, <#size_t height#>, <#size_t bitsPerComponent#>, <#size_t bytesPerRow#>, <#CGColorSpaceRef space#>, <#CGBitmapInfo bitmapInfo#>)
    
    
    
    
}
@end
